<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- <input autofocus="autofocus" /> -->
    <hr />
    <div id="app">
      <input type="text" v-focus />
      <div v-click-outside="hide">
        <input type="text" @focus="show" />
        <section v-if="isShow">选择时间</section>
      </div>
    </div>
  </body>
  <script src="./node_modules/vue/dist/vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data() {
        return {
          isShow: false
        }
      },
      methods: {
        show() {
          this.isShow = true
        },
        hide() {
          this.isShow = false
        }
      },
      directives: {
        focus: {
          inserted(el) {
            el.focus()
          }
        },
        clickOutside(el, bindings, vnode) {
          document.addEventListener('click', (e) => {
            if (!el.contains(e.target)) {
              const method = bindings.expression
              vnode.context[method]()
            }
          })
        }
      }
    })
  </script>
</html>
